// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   TouchHandlerOld.java

package org.achartengine;

import android.graphics.RectF;
import android.view.MotionEvent;
import org.achartengine.chart.AbstractChart;
import org.achartengine.chart.RoundChart;
import org.achartengine.chart.XYChart;
import org.achartengine.renderer.DefaultRenderer;
import org.achartengine.tools.Pan;
import org.achartengine.tools.PanListener;
import org.achartengine.tools.ZoomListener;

// Referenced classes of package org.achartengine:
//			ITouchHandler, GraphicalView

public class TouchHandlerOld
	implements ITouchHandler
{

	private DefaultRenderer mRenderer;
	private float oldX;
	private float oldY;
	private RectF zoomR;
	private Pan mPan;
	private GraphicalView graphicalView;

	public TouchHandlerOld(GraphicalView graphicalview, AbstractChart abstractchart)
	{
		zoomR = new RectF();
		graphicalView = graphicalview;
		zoomR = graphicalView.getZoomRectangle();
		if (abstractchart instanceof XYChart)
			mRenderer = ((XYChart)abstractchart).getRenderer();
		else
			mRenderer = ((RoundChart)abstractchart).getRenderer();
		if (mRenderer.isPanEnabled())
			mPan = new Pan((XYChart)abstractchart);
	}

	public boolean handleTouch(MotionEvent motionevent)
	{
		int i = motionevent.getAction();
		if (mRenderer != null && i == 2)
		{
			if (oldX >= 0.0F || oldY >= 0.0F)
			{
				float f = motionevent.getX();
				float f1 = motionevent.getY();
				if (mRenderer.isPanEnabled())
					mPan.apply(oldX, oldY, f, f1);
				oldX = f;
				oldY = f1;
				graphicalView.repaint();
				return true;
			}
		} else
		if (i == 0)
		{
			oldX = motionevent.getX();
			oldY = motionevent.getY();
			if (mRenderer != null && mRenderer.isZoomEnabled() && zoomR.contains(oldX, oldY))
			{
				if (oldX < zoomR.left + zoomR.width() / 3F)
					graphicalView.zoomIn();
				else
				if (oldX < zoomR.left + (zoomR.width() * 2.0F) / 3F)
					graphicalView.zoomOut();
				else
					graphicalView.zoomReset();
				return true;
			}
		} else
		if (i == 1)
		{
			oldX = 0.0F;
			oldY = 0.0F;
		}
		return !mRenderer.isClickEnabled();
	}

	public void addZoomListener(ZoomListener zoomlistener)
	{
	}

	public void removeZoomListener(ZoomListener zoomlistener)
	{
	}

	public void addPanListener(PanListener panlistener)
	{
		if (mPan != null)
			mPan.addPanListener(panlistener);
	}

	public void removePanListener(PanListener panlistener)
	{
		if (mPan != null)
			mPan.removePanListener(panlistener);
	}
}
